﻿using System.Collections.Generic;
using System.Linq;
using Missbot.Service;

namespace Missbot.AIModule.Sys
{
    public class VersionInfo : DbBaseEntity
    {
        public string Name { get; set; }

        public string VersionNum => Name;

        public string PublishDate { get; set; }

        public string[] WhatsNewList { get; set; }
    }

    public static class VersionInfoDA
    {
        public static string Format(this VersionInfo entity)
        {
            var newListMsg = string.Join("\n", entity.WhatsNewList.Select((n, idx) => $"{idx + 1}.{n}"));
            var msg = $"版本号：{entity.VersionNum}\n发布日期：{entity.PublishDate}\n发布内容：\n{newListMsg}";
            return msg;
        }

        public static IEnumerable<VersionInfo> GetAll()
        {
            return MongoService<VersionInfo>.Get();
        }
    }
}